package com.jet.chat.command;

import java.util.regex.Matcher;

import com.jet.chat.exception.ChatException;
import com.jet.chat.message.Message;
import com.jet.chat.server.ChatServer;
import com.jet.chat.server.ChatSession;


public class ChatCommandListChannelUsers extends ChatCommandAbstract {
	public ChatCommandListChannelUsers() {
		super("^/\\w+$");
	}

	@Override
	protected void executeCommand(Matcher matcher, ChatServer chatServer, ChatSession chatSession, Message chatMessage) throws ChatException {
		String responce = "";
		for (ChatSession existedSession : chatServer.getChannel(chatSession.getChannelName()).getSessions()) {
			responce = responce + existedSession.getUsername() + "\r\n";
		}
		chatSession.getQueue().addMessage(responce);
	}

}
